Replace synchronized(this) with lock-free initState in LazyList#26100
Replace synchronized(this) with lock-free initState in LazyList#26100lrytz wants to merge 4 commits into
Conversation
b77e7d7 to
32723dc
Compare
|
Does this need to be also done for |
Is interesting. For When adding a lazy val to an So adding a lazy val to an existing object triggers MiMa, the class initializer turns from public to private. It's safe to ignore, the method is only invoked by the JVM and it can be private. But it seems worth aligning to avoid the MiMa flag. |
|
IMO MiMa is just wrong here and should never report anything about |
JDK 23+ allocates `ObjectMonitor` instances in native memory eagerly in the single-threaded case under nested recursive synchronized blocks. This can lead to huge memory consumption while evaluating LazyLists. This commit replaces synchronized with a lock-free coordination.
b478e78 to
0135565
Compare
its the same file copy pasted with Seq parent type removed, so yeah :) |
|
This seems to pass CI now. @natsukagami would you have time to provide the right capture annotations and |
|
|
||
| def InRace(t: Thread): InRace = throw new Exception("unreachable") | ||
|
|
||
| final class InRace private[LazyListBase] (val owner: Thread) { |
There was a problem hiding this comment.
As suggested in the Scala 2.js version of this PR (scala-js/scala-js#5358):
| final class InRace private[LazyListBase] (val owner: Thread) { | |
| final class InRace private[LazyListBase] () { | |
| throw new Exception("unreachable") | |
| def owner: Thread = throw new Exception("unreachable") |
JDK 23+ allocates
ObjectMonitorinstances in native memory eagerly in the single-threaded case under nested recursive synchronized blocks.This can lead to huge memory consumption while evaluating LazyLists.
This commit replaces
synchronizedwith a lock-free coordination.Forward-port of scala/scala#11242.
Fixes #25777
How much have you relied on LLM-based tools in this contribution?
Moderately, for diagnosing the issue, reviewing my code, writing tests.
How was the solution tested?